1   /*
2    * GenericDatabaseTest.java
3    * JUnit based test
4    *
5    * Created on December 21, 2004, 3:18 PM
6    */
7   
8   package gov.noaa.eds.xapi.generic;
9   
10  import junit.framework.*;
11  import java.util.Hashtable;
12  import org.xmldb.api.base.Collection;
13  import org.xmldb.api.base.Database;
14  import org.xmldb.api.base.ErrorCodes;
15  import org.xmldb.api.base.XMLDBException;
16  
17  /***
18   *
19   * @author tns
20   */
21  public class GenericDatabaseTest extends TestCase {
22      
23      GenericDatabase database = null;
24      private static String collectionName = "xmldb:generic://www.eatmutton.com/Test Collection";
25      
26      public GenericDatabaseTest(String testName) {
27          super(testName);
28      }
29  
30      protected void setUp() throws java.lang.Exception {
31          database = new GenericDatabase();
32          
33          // TODO add your test code below by replacing the default call to fail.
34          GenericCollection collection = new GenericCollection();
35          collection.setName(collectionName);
36          database.addCollection(collection);
37      }
38  
39      protected void tearDown() throws java.lang.Exception {
40          database = null;
41      }
42  
43      public static junit.framework.Test suite() {
44          junit.framework.TestSuite suite = new junit.framework.TestSuite(GenericDatabaseTest.class);
45          
46          return suite;
47      }
48  
49      /***
50       * Test of addCollection method, of class gov.noaa.eds.xapi.generic.GenericDatabase.
51       */
52      public void testAddCollection() throws Exception {
53          System.out.println("testAddCollection");
54          
55          
56          Collection col = database.getCollection(collectionName,null,null);
57          assertNotNull("non-null collection expected.",col);
58      }
59  
60      /***
61       * Test of acceptsURI method, of class gov.noaa.eds.xapi.generic.GenericDatabase.
62       */
63      public void testAcceptsURITrue() {
64  
65          boolean test = this.database.acceptsURI(collectionName);
66          assertTrue("Expected database to accept URI",test);
67          
68          
69      }
70      
71      /***
72       * Test of acceptsURI method, of class gov.noaa.eds.xapi.generic.GenericDatabase.
73       */
74      public void testAcceptsURIFalse() {
75          System.out.println("testAcceptsURI");
76  
77          boolean test = this.database.acceptsURI("xmldb:generic://somewhere.com/Col");
78          assertFalse("Expected database to not accept the URI",test);
79          
80          
81      }
82      
83  
84      /***
85       * Test of getNames method, of class gov.noaa.eds.xapi.generic.GenericDatabase.
86       */
87      public void testGetNames() {
88          System.out.println("testGetNames");
89          
90          // TODO add your test code below by replacing the default call to fail.
91          String[] names = database.getNames();
92          assertNotNull("names should not return null",names);
93          assertEquals("Should be one collection name",names.length,1);
94          this.assertEquals("Collection name was wrong",names[0],collectionName);
95      }
96  
97      /***
98       * Test of getConformanceLevel method, of class gov.noaa.eds.xapi.generic.GenericDatabase.
99       */
100     public void testGetConformanceLevel() {
101         System.out.println("testGetConformanceLevel");
102         database.setConformanceLevel("Core Level 1");
103         String level = database.getConformanceLevel();
104         assertNotNull("level should not be null",level);
105         assertEquals("returned level not the same as set level",level,"Core Level 1");
106         
107     }
108     
109     public void testGetDefaultConformanceLevel(){
110         String level = database.getConformanceLevel();
111         assertNotNull("default conformance level should not be null",level);
112         assertEquals("returned level is not the expected default","Core Level 1",level);
113     }
114 
115     /***
116      * Test of setConformanceLevel method, of class gov.noaa.eds.xapi.generic.GenericDatabase.
117      */
118     public void testSetConformanceLevel() {
119         database.setConformanceLevel("Core 1");
120         
121         // TODO add your test code below by replacing the default call to fail.
122     }
123 
124     /***
125      * Test of getCollection method, of class gov.noaa.eds.xapi.generic.GenericDatabase.
126      */
127     public void testGetCollection() throws Exception {
128         System.out.println("testGetCollection");
129         
130         // TODO add your test code below by replacing the default call to fail.
131         Collection col = database.getCollection(collectionName,null,null);
132         assertNotNull("Collection should not be null",col);
133         assertEquals("Returned collection had a different name than expected",collectionName,col.getName());
134     }
135     
136     // TODO add test methods here. The name must begin with 'test'. For example:
137     // public void testHello() {}
138     
139 }